package cn.hrlly.tao2shou.biz;

import android.content.Context;

import com.zhy.http.okhttp.OkHttpUtils;

import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.callback.OrderListCallback;
import cn.hrlly.tao2shou.domain.OrderList;
import cn.hrlly.tao2shou.listener.OnOrderListListener;
import cn.hrlly.tao2shou.utils.CacheUtil;

/**
 * User: gengliang
 * Date: 2016-01-31
 * Time: 14:17
 */

public class OrderListBizImpl implements OrderListBiz {

    private OnOrderListListener onOrderListListener;
    private CacheUtil cacheUtil;

    public OrderListBizImpl(OnOrderListListener onOrderListListener,Context context) {
        this.onOrderListListener = onOrderListListener;
        this.cacheUtil=new CacheUtil(context);
    }

    @Override
    public void getNetOrderList(OrderList orderList) {
        OkHttpUtils
                .post()
                .url(Config.key_url)
                .addParams(Config.key_action,Config.action_order_list)
                .addParams(Config.key_order_type, String.valueOf(orderList.getOrderType()))
                .build()
                .execute(new OrderListCallback(onOrderListListener));
    }

    @Override
    public void saveCacheBuyerUnfinishOrderList(OrderList orderList) {
        cacheUtil.putBuyerUnfinishOrder(orderList);
    }

    @Override
    public void saveCacheBuyerCompleteOrderList(OrderList orderList) {
        cacheUtil.putBuyerCompleteOrder(orderList);
    }

    @Override
    public void saveCacheSellerUnfinishOrderList(OrderList orderList) {
        cacheUtil.putSellerUnfinishOrder(orderList);
    }

    @Override
    public void saveCacheSellerCompleteOrderList(OrderList orderList) {
        cacheUtil.putSellerCompleteOrder(orderList);
    }

    @Override
    public OrderList getCacheBuyerUnfinishOrderList() {
        OrderList orderList=cacheUtil.getBuyerUnfinishOrder();
        return orderList;
    }

    @Override
    public OrderList getCacheBuyerCompleteOrderList() {
        OrderList orderList=cacheUtil.getBuyerCompleteOrder();
        return orderList;
    }

    @Override
    public OrderList getCacheSellerUnfinishOrderList() {
        OrderList orderList=cacheUtil.getSellerUnfinishOrder();
        return orderList;
    }

    @Override
    public OrderList getCacheSellerCompleteOrderList() {
        OrderList orderList=cacheUtil.getSellerCompleteOrder();
        return orderList;
    }
}
